﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Configuration;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseMachineinfo : System.Web.UI.Page
    {
        ///当前市场
        protected string CurrentArea
        {
            get
            {
                return ConfigurationManager.AppSettings["sysArea"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Guid MacGuid = Guid.Empty;
                if (!string.IsNullOrEmpty(Context.Request["status"]))
                {
                    hdStatus.Value = Context.Request["status"];
                }
                if (!string.IsNullOrEmpty(Context.Request["mid"]))
                {
                    hdID.Value = Context.Request["mid"];
                }
                if (!string.IsNullOrEmpty(Request.QueryString["MacGuid"]))
                {
                    if (Guid.TryParse(Request.QueryString["MacGuid"], out MacGuid))
                    {
                        hdMacGuid.Value = MacGuid.ToString();
                    }
                }
                else
                {
                    MacGuid = Guid.NewGuid();
                    hdMacGuid.Value = MacGuid.ToString(); ;
                }
                Initial();
                
            }
        }

        #region 页面初始化
        private void Initial()
        {
            BindDropDownList();
            if (hdStatus.Value == "0")
            {
                txtID.Visible = false;
            }
        }

        /// <summary>
        /// 取得字典数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected Dictionary<string, string> GetGetDictionary(string type, string condition)
        {
            using (BasicService.BasicServiceClient client = new BasicService.BasicServiceClient())
            {
                return JsonConvert.DeserializeObject<Dictionary<string, string>>(client.GetDictionary(type, condition, CurrentArea));
            }
        }
        /// <summary>
        /// 绑定下拉列表
        /// </summary>
        private void BindDropDownList()
        {
            ////设备是自有或租赁
            DropIsOwn.DataSource = GetGetDictionary("machineisown", "");
            DropIsOwn.DataTextField = "value";
            DropIsOwn.DataValueField = "key";
            DropIsOwn.DataBind();
            DropIsOwn.Items.Insert(0, new ListItem("请选择", "-1"));
        }
        #endregion

        


    }
}
